package 回溯法;

/**
 * Copyright (C) 2023 思创数码科技股份有限公司
 * <p/>
 * 版权所有
 * <p/>
 * 类名　　  : FindTargetSum
 * 功能概要  :
 *
 * @author yangwk
 * @date 2024/6/30 16:33
 */
public class 查找目标数 {
    public static   int findTargetSumWays(int[] nums, int target) {
        return findWays(nums, 0, target, 0);
    }

    public static int findWays(int[] nums,int cur,int target,int depth){
        int result = 0;
        if(depth>=nums.length){
            if(cur==target){
                return result+1;
            }else{
                return result;
            }
        }
        result += findWays(nums, cur + nums[depth], target, depth + 1);
        result += findWays(nums, cur - nums[depth], target, depth + 1);
        return result;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1, 1, 1, 1, 1};
        System.out.println(findTargetSumWays(nums, 3));
    }
}
